{extend name="public/base"/}
{block name="style"}
<script src="/public/cartoon/js/layer.js"></script>
<script type="text/javascript">
<!--
	document.oncontextmenu=new Function("event.returnValue=false");
	document.onselectstart=new Function("event.returnValue=false");
//-->

</script>
{/block}
{block name="body"}
<style>
    .menuBox li {
        float: left;
        width: 55px;
        height: 35px;
        line-height: 35px;
        text-align: center;
        font-size: 16px;
        -moz-border-radius: 8px;
        border-radius: 8px;
    }
</style>
{include file="public/header" /}

<div class="pageBox contentTit" >
当前位置：<a href="/">{$Think.config.web_site_title}</a> > <a href="/books">{$category}</a> > <a href="{:url('/book/info',array("id"=>$bookid))}">{$bookname}</a>
</div>
<div class="pageBox contentBox" >
    <h1>{$chaptername}</h1>
    <span>更新时间：{$update_time} 本章字数：{$size}</span>
    <div class="Cbox">
		
    </div>
    <div class="readShang"><span></span></div>
</div>
<div class="pageBox showPage" >
	{prev articleid="$bookid" chapterid="$chapterid" model="chapter"}
    <div class="{$randomStr} showUpBox {$randomStr}">（快捷键 <-）<a href="JavaScript:;" onclick="goread{$randomStr}({if $prev.isvip==1}true{else}false{/if}, {$prev.saleprice}, '/chapter/read/{$bookid}/{$prev['id']}')">上一页</a></div>
    {/prev}
    <div class="{$randomStr} showCBox {$randomStr}"><a href="/book/chapter/{$bookid}">目录</a></div>
    {next articleid="$bookid" chapterid="$chapterid" model="chapter"}
    <div class="{$randomStr} showNextBox {$randomStr}"><a href="JavaScript:;" onclick="goread{$randomStr}({if $next.isvip==1}true{else}false{/if}, {$next.saleprice}, '/chapter/read/{$next.articleid}/{$next.id}')">下一页</a>（快捷键 ->）</div>
    {/next}
</div>
<div class="MaskBox" id="pc_mask_box" style="display:none;z-index:9999">
	<div class="MaskUgoD">
		<div class="MaskClose">X</div>
		<ul class="clearfix" id="uGoBox">
			{volist name="bonusconfig" id="vo"}
			<li data-price="{$vo.price}" data-type="{$key}" style="background:url({$vo.imgfile}) no-repeat top center; background-size:60px;">
				<span>打赏{$vo.caption}</span>
			</li>
			{/volist}
		</ul>
		<div class="dsInfo">
			<div class="dsDescBox">选择以上打赏种类</div>
			<div class="dsDoBox" data-type="-1">确认打赏
			</div>
		</div>
	</div>
</div>

{block name="include"}{include file="public:footer" /}{/block}

{/block}
{block name="script"}

	<script type="text/javascript" src="__PUBLIC__/static/js/jquery.cookie.js"></script>
	<script type="text/javascript">
	//阅读页面添加cookie
	var articleid = '{$bookid}';
	var articlename = '{$bookname}';
	var chapterid = '{$chapterid}';
	var chaptertitle = '{$chaptername}';
	var articleurl = '/book/info/id/'+articleid+'.html';
	var chapterurl = '/chapter/read/'+articleid+'/'+chapterid+'.html';
	var img = "{$cover}";
	var category = '{$category}';
	var fullflag = '{$fullflag}';
	var allvisit = {$allvisit};
	var Cbox{$randomStr} = '{$chaptercontent|json_encode}';
	//此书是否收藏
	var collect = '{$collect}';
	<!--
		var json1 = "";
		if (!$.cookie("history")) {
				//第一次的时候需要初始化
				$.cookie("history", "{title:\"" + chaptertitle + "\"" + ",book:\"" + articlename + "\"" + ",bookid:\"" + articleid + "\"" + ",chapterid:\"" + chapterid + "\"" + ",img:\"" + img + "\"" + ",url:\"" + chapterurl + "\"" + ",category:\"" + category + "\"" + ",fullflag:\"" + fullflag + "\"" + ",allvisit:\"" + allvisit + "\"" + ",aurl:\"" + articleurl + "\"}", {expires: 7, path: '/'});
		} else {

				var json = eval("(" + $.cookie("history") + ")");
				json1 = json1 + "[{title:\"" + chaptertitle + "\"" + ",book:\"" + articlename + "\"" + ",bookid:\"" + articleid + "\"" + ",chapterid:\"" + chapterid + "\"" + ",img:\"" + img + "\"" + ",url:\"" + chapterurl + "\"" + ",category:\"" + category + "\"" + ",fullflag:\"" + fullflag + "\"" + ",allvisit:\"" + allvisit + "\"" + ",aurl:\"" + articleurl + "\"}";
				$(json).each(function () {
					if ((this.book != articlename)) {
						json1 = json1 + ",{title:\"" + this.title + "\"" + ",book:\"" + this.book + "\"" + ",bookid:\"" + this.bookid + "\"" + ",chapterid:\"" + chapterid + "\"" + ",img:\"" + this.img + "\"" + ",url:\"" + this.url + "\"" + ",category:\"" + this.category + "\"" + ",fullflag:\"" + this.fullflag + "\"" + ",allvisit:\"" + this.allvisit + "\"" + ",aurl:\"" + this.aurl + "\"}";
					}
				});
				json1=json1+"]";
				$.cookie("history", json1, {expires: 7, path: '/'});
		}
	-->
	</script>
	<!--签到-->
	<script type="text/javascript">
		 $('#iosDialog2').on('click', '.weui-dialog__btn', function(){
		 	var cnumber = $('.cnumber').text()
            $(this).parents('.js_dialog').fadeOut(200);
            $.ajax({
                type: 'GET',
                url:'',
                dataType: 'json',
                success: function(data){
                	
                },
                error: function(xhr, type){
                    console.log(cnumber);
                }
            });
        });
		function addBookcase(articleid){
			$.ajax({
				url:'/book/bookcase',
				async: false,
				dataType:'json',
				data : {'articleid':articleid},
				type:'post',
				success:function(json){
					if(json.code==1){
	            		$('#pc_mask_box').hide();
					}else if(json.code==2){
						layer.msg(json.msg, {icon: 2});
					}else{
						layer.msg(json.msg, {icon: 2});
						setTimeout(function () {
								location.href = "/pay/index";
						}, 2000)
					}

					if(json.code==1){
						layer.msg('成功加入书架', {icon: 1});
						$('.art-tipsbar').hide();
					}else{
						layer.msg('加入书架失败', {icon: 2});
					}
				},
				error:function(){
					
				}
			});
		}
    	//打赏
    	$(document).on("click", ".readShang", function () {
            {if $Think.session.user_auth.uid==null}
            $.loginBox();
            return;
            {/if}
    		$('#pc_mask_box').show();
	    });

	    $(document).on("click", "#uGoBox li", function () {
	        var text = $(this).find("span").text();
	        var price = $(this).attr("data-price");
	        var type = $(this).attr("data-type");
	        $(".dsDoBox").attr("data-type", type);
	        $(".dsDescBox").text(text + "所需" + price + "币");
	    });

		$(document).on('click', '.dsDoBox', function(){
			var type = $(this).attr("data-type");			
			if(type==-1)
				return;
	    	$.ajax({
	            type: 'POST',
	            url:'/book/bookbonus',
	            dataType: 'json',
				data : {'articleid':articleid,'actname':type,'num':1},
	            success: function(json){
					if(json.code==1){
						layer.msg(json.msg, {icon: 1});
	            		setTimeout(function () {
							$('#pc_mask_box').hide();
						}, 2000)
					}else if(json.code==2){
						layer.msg(json.msg, {icon: 2});
					}else{
						layer.msg(json.msg, {icon: 2});
						setTimeout(function () {
								location.href = "/pay/index";
						}, 2000)
					}
	            },
	            error: function(xhr, type){

	            }
	        });
	    });

		function jumpPage(event){

			var key = window.event ? event.keyCode : event.which;
			if (key==37){//左
				{prev articleid="$bookid" chapterid="$chapterid" model="chapter"}
					window.location.href="/chapter/read/{$bookid}/{$prev['id']}";
			    {/prev}
			} 
			if (key==39){//右
				{next articleid="$bookid" chapterid="$chapterid" model="chapter"}
					window.location.href="/chapter/read/{$bookid}/{$next['id']}";
			    {/next}
			} 
		}
		document.onkeydown=jumpPage;

        function goread{$randomStr}(vip, saleprice, url){
            if(vip){
                {if $Think.session.user_auth.uid==null}
                $.loginBox(url);
                return;
                {/if}
            }
            window.location.href = url;
        }
		
		$(function(){
			var html ='';
			$.each(eval(Cbox{$randomStr}).reverse(), function(i, v) {
				html +=v;
			})
			$(".Cbox").html(html);
		})
	</script>
{/block}